package com.example.android.ui.detail;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.widget.Toolbar;

import com.example.android.R;
import com.example.android.bean.GoodsDetail;
import com.example.android.ui.base.BaseActivity;
import com.example.android.ui.base.BaseFragment;

public class GoodsDetailActivity extends BaseActivity implements View.OnClickListener, GoodsDetailContract.IGoodsDetailView {

    public static final String GOODS_ID = "goods_id";
    private GoodsDetailPresenter goodsDetailPresenter;
    private TextView content, title;
    private ImageView back;

    @Override
    protected void initViews() {
        title = find(R.id.goods_detail_title);
        back = find(R.id.goods_detail_back);

        content = find(R.id.detail_content);
        int goodsId = getIntent().getIntExtra(GOODS_ID, 0);
        goodsDetailPresenter = new GoodsDetailPresenter(this);
        goodsDetailPresenter.getGoodsDetail(goodsId);
        //点击事件
        back.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_goods_detail;
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.goods_detail_back:
                finish();
                break;
            default:
                break;
        }

    }

    @Override
    public void getGoodsDetailSuccess(GoodsDetail goodsDetail) {
        title.setText(goodsDetail.getName());
        content.setText(goodsDetail.getDescription());
    }

    @Override
    public void getGoodsDetailError(Throwable throwable) {

    }
}
